Ext.define('PJ.view.setassessmentpaper.ChooseSelectStaffList', {
    extend: 'AM.default.DefaultList',
    
    alias: ['widget.chooseSelectStaffList'],
    
    title: '已选列表',
    
    
    queryUnitId: null,
    //height: 269,
    overflowX: 'auto',
    overflowY: 'hidden',
    columns: [{
        header: '问卷名称',
        dataIndex: 'questionnaireName',
        flex: 1,
        minWidth: 120,
		renderer: function(value, metaData, record){
			metaData.tdAttr = 'data-qtip="' + value + '"';
			return value;
		}
    },{
        header: '问卷说明',
        dataIndex: 'questionnaireExplain',
        flex: 1,
        minWidth: 120,
        renderer: function(value, metaData, record){
            return value;
        }
    },{
        header: '创建时间',
        dataIndex: 'q.createDate',
        width: 100,
        renderer: function(value, metaData, record){
            return value;
        }
    }],
    
    initComponent: function(){
        this.store = Ext.create('PJ.store.setassessmentpaper.ChooseSelectStaffList');
        this.loadType = gj_onlineLearning_constant.loadType;//加载方式
        this.callParent(arguments);
    },
    
    onDeleteClick: function(button){
        var me = this;
        var records = this.getSelectionModel().getSelection();
        Ext.Msg.confirm({
            title: '提示',
            msg: '您确定要删除这些信息吗?',
            buttons: Ext.Msg.OKCANCEL,
            fn: function(id){
                if (id == 'ok') {
//                    me.loadMask.show();
                    var questionnaireIds = new Array();
                    Ext.Array.each(records, function(name, index){
                    	questionnaireIds.push(name.get("questionnaireId"));
                    });
                    
                    if(gj_onlineLearning_constant.loadType == "jsonp"){
                    	var store = Ext.create('AM.default.jsonp.DefaultAjaxStore',{
                            url: me.store.deleteUrl,
                            extraParams: { //请求的相关参数
                            	questionnaireIds: questionnaireIds,
                            	classId: me.up("window").classId
                            },
                            loadType:gj_onlineLearning_constant.loadType//View层的loadType调整，用来切换是否需要以JSONP方式请求。
                        });
                        store.load(function(rec, operation, success){
//                        	me.loadMask.hide();
                             if (success) {//json返回结果中的success是否成功
                            	 Ext.create('AM.default.DefaultAlertBox', {
                                     title: '消息',
                                     msg: '删除成功！',
                                     fn: function(){
                                         var store = me.getStore();
                                         store.load();
                                         me.up("window").down("preSelectStaffList").getStore().load();
                                         me.up("window").grid.getStore().load();
                                     }
                                 });
                             }else {
                            	 if (operation.error) {
                                     Ext.create('AM.default.DefaultAlertBox', {
                                         title: '消息',
                                         msg: operation.error,
                                         fn: function(){
                                             var store = me.getStore();
                                             store.load();
                                             me.up("window").down("preSelectStaffList").getStore().load();
                                             me.up("window").grid.getStore().load();
                                         }
                                     });
                                 }
                                 else {
                                     Ext.create('AM.default.DefaultAlertBox', {
                                         title: '消息',
                                         msg: '删除失败！',
                                         fn: function(){
                                             var store = me.getStore();
                                             store.load();
                                             me.up("window").grid.getStore().load();
                                         }
                                     });
                                 }
                            }
                        });
                    }else if(gj_onlineLearning_constant.loadType == "ajax"){
                    	Ext.Ajax.request({
                            url: me.store.deleteUrl,
                            params: {
                            	questionnaireIds: questionnaireIds,
                            	classId: me.up("window").classId
                            },
                            success: function(response){
//                                me.loadMask.hide();
                                var data = response.responseText;
                                var json = Ext.decode(data, true);
                                if (json.success) {
                                	Orchid.alert('消息', '删除成功！', function(){
                                        var store = me.getStore();
                                        store.load();
                                        // 刷新已选面板
                                        me.up("window").down("preSelectStaffList").getStore().load();
                                        me.up("window").grid.getStore().load();
                                    });
                                }
                                else {
                                	Orchid.alert('消息', json.msg, function(){
                                        var store = me.getStore();
                                        store.load();
                                        me.up("window").grid.getStore().load();
                                    });
                                }
                            }
                        });
                    }
                }
                else {
                    return;
                }
            }
        });
    },
    listeners: {
        selectionchange: function(selModel, selected){
            this.down('#' + this.oldId + "Delete").setDisabled(selected.length === 0);
		},
        viewready: function(){
        	var me = this;
            this.addDocked([/*{
                dock: 'top',
                xtype: "searchform",
                columnCount: 1,
//                collapsed:true,
                fieldDefaults: {
                    labelAlign: 'right',
                    labelWidth: 100
                },
                items: [{
    				xtype: "textfield",
    				fieldLabel: '问卷名称',
    				name: "searchQuestionnaireName",
    				maxLength: "50",
    				emptyText: "请输入问卷名称"
    			}],
                grid: this,
                onResetClick: function(button){
                    var form = button.up('form');
                    var gridPanel = form.grid;
                    var newParams = {
                    		searchType: "selected",
                    		searchTrainingRoleId: me.up("window").trainingRoleId,
                    		searchClassId: me.up("window").classId
                    };
                    gridPanel.getStore().proxy.extraParams = {};
                    
                    var params = gridPanel.getStore().proxy.extraParams;
                    Ext.apply(params, newParams);
                    
                    form.getForm().reset();
                }
            },*/{
                xtype: 'toolbar',
                dock: 'top',
                displayInfo: true,
                items: [this.deleteButton,"->", "->", this.countSelectPanel]
            }]);
            // 触发权限过滤事件
            this.fireEvent("permission", this);
            var store = me.getStore();
            var frame = me.up("selectStaffRightFrame");
    		if(!frame){
    			frame = me.up("selectStaffRightCourseFrame");
    		}
            var newParams = {
            		searchType: "selected",
            		surveyObjectId: frame.classId
            };
            var params = me.getStore().proxy.extraParams;
            Ext.apply(params, newParams);
            store.isLoad = true;
            store.load();
        },
        afterrender: function(){
            this.loadMask = new Ext.LoadMask(this, {
                msg: "正在加载中,请稍后...."
            });
        }
    }
});
